package game.engine;

import org.newdawn.slick.Animation;
import org.newdawn.slick.geom.*;

public abstract class Entity {
	protected String name;
	protected World myWorld;
	protected Animation currentSprite;
	protected Vector2f moveVector = new Vector2f(0.0f, 0.0f);
	protected float x;
	protected float y;
	protected String graphicsDir;

	public abstract void init();

	public void setWorld(World w) {
		myWorld = w;
	}

	public Vector2f getMoveVector() {
		return moveVector;
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

	public boolean attemptMove() {
		if (myWorld.isSpaceOpen(moveVector, x, y)) {
			x += moveVector.getX();
			y += moveVector.getY();
			return true;
		}
		else {
			return false;
		}
	}

	public boolean checkEntityCollision(Entity e) {
		if (e != this) {
			return CollisionUtilities.intersectBounds(getBounds(), e.getBounds());
		}
		return false;
	}

	public Rectangle getBounds() {
		Rectangle bounds = new Rectangle(x, y, currentSprite.getWidth(), currentSprite.getHeight());
		return bounds;
	}

	public int getSpriteWidth() {
		return currentSprite.getWidth();
	}

	public int getSpriteHeight() {
		return currentSprite.getHeight();
	}

	public void draw(int x, int y) {
		currentSprite.draw(x, y);
	}

	public void takeDamage(int damage) {
	}

	public abstract void update();

	public void updateGraphics(long delta) {
		currentSprite.update(delta);
	}

	public Animation getCurrentSprite() {
		return currentSprite;
	}

	public String getName() {
		return name;
	}
}
